Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix threaded sam_read1 after EOF. #1856

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

jkbonfield
Copy link
Contributor

The SAM sam_dispatcher_read decodes blocks of SAM records into blocks of BAM records. As this is (hopefully) reading ahead of the sam_read1 consumer code, when it hits EOF it adds a final NULL block as a sentinel. This works well and it forces sam_read1 to return EOF too.

However, if we ignore that and call sam_read1 again, it's consumed our sentinel block and it gets stuck waiting for the next block of BAM records. We now cache the EOF status and check first.

Note this doesn't impact on iterators as they work at a different level already and it's the iterator itself which tracks EOF.

Fixes #1855

The SAM sam_dispatcher_read decodes blocks of SAM records into blocks
of BAM records.  As this is (hopefully) reading ahead of the sam_read1
consumer code, when it hits EOF it adds a final NULL block as a
sentinel.  This works well and it forces sam_read1 to return EOF too.

However, if we ignore that and call sam_read1 again, it's consumed our
sentinel block and it gets stuck waiting for the next block of BAM
records.  We now cache the EOF status and check first.

Note this doesn't impact on iterators as they work at a different
level already and it's the iterator itself which tracks EOF.

Fixes samtools#1855
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sam_read1 stuck after reaching end of the SAM file when using hts_tpool
2 participants